package org.example.codegenerate.service.impl;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@Slf4j
@Data
public class DataTo {
    //private static final Logger log = LoggerFactory.getLogger(org.jeecgframework.codegenerate.generate.getCworkspaceJeecg.getCworkspaceJeecg.class);
    private String templateDirRelative;///jeecg/code-template-online
    private List<File> fileList = new ArrayList();
    private String _stylePath;//default.one
    private File currentTemplateDirFileAbsolute;//E:\gitcategory\codegenerate\novagenerate\jeecg-boot-module-system\target\classes\jeecg\code-template-online
    private File currentSelectedFile;//E:\gitcategory\codegenerate\novagenerate\jeecg-boot-module-system\target\classes\jeecg\code-template-online\default\one\java\${bussiPackage}\${entityPackage}\controller\${entityName}Controller.javai
    private String templateFile;//default\one\java\${bussiPackage}\${entityPackage}\controller\${entityName}Controller.javai
    public DataTo(String _templateDir) {
        log.debug("----templatePath-----------------" + _templateDir);
        log.debug("----stylePath-----------------" + this._stylePath);
        this.templateDirRelative = _templateDir;
    }

    private void setFile(File file) {
        this.setFileList(file);
    }

    private void setFileList(File... var1) {
        this.fileList = Arrays.asList(var1);
    }

    public String getStylePath() {
        return this._stylePath;
    }

    public void setStylePath(String stylePath) {
        this._stylePath = stylePath;
    }
    //获取该目录下所有文件
    public List<File> getFileList() {
        String templatepath = this.getClass().getResource(this.templateDirRelative).getFile();
        templatepath = templatepath.replaceAll("%20", " ");
        log.debug("-------classpath-------" + templatepath);
        if (templatepath.indexOf("/BOOT-INF/classes!") != -1 || templatepath.indexOf("/BOOT-INF/lib/") != -1) {
            templatepath = System.getProperty("user.dir") + File.separator + "config/jeecg/code-template-online/".replace("/", File.separator);
            log.debug("---JAR--config--classpath-------" + templatepath);
        }

        this.setFile(new File(templatepath));//含有目录
        return this.fileList;
    }

    public void getFileList(List<File> var1) {
        this.fileList = var1;
    }

    public String toString() {
        StringBuilder var1 = new StringBuilder();
        var1.append("{\"templateRootDirs\":\"");
        var1.append(this.fileList);
        var1.append("\",\"stylePath\":\"");
        var1.append(this._stylePath);
        var1.append("\"} ");
        return var1.toString();
    }
}